#include <iostream>
#include <stdio.h>

void bucket_sort(int *arr, int size, int max);
void show(int *arr, int len);

int main()
{
    int a[7] = {1, 2, 4, 5, 3, 9, 8};
    //数组长度
    int num = sizeof(a) / sizeof(a[0]);

    bucket_sort(a, num, num);

    show(a, num);

    return 0;
}

void bucket_sort(int *arr, int size, int max)
{
    int i, j;
    int buckets[max];
    memset(buckets, 0, max * sizeof(int));
    for (i = 0; i < size; i++)
    {
        buckets[arr[i]]++;
    }
    for (i = 0, j = 0; i < max; i++)
    {
        while ((buckets[i]--) > 0)
            arr[j++] = i;
    }
}

void show(int *arr, int len)
{
    for (int i = 0; i < len; i++)
    {
        printf("%d ", arr[i]);
    }
    printf("\n");
}